#!/usr/bin/env node
require('shelljs/global')

let SynObj = require('../jce/SynchronousProxy').News
// require('../main')
let argv = require('yargs')
    .command("c", 'grab_source_conf', function (yargs) {
        echo('success')
        let argv = yargs.reset()
            .help('h')
            .alias('h', 'help')
            .argv
        // for(let arg of argv._){
        //     echo(arg)
        // }
     echo(syn(argv._))

    })
    .command("r","t_crawler_rule",function (yargs) {

    })
    .command("a",'all difInfo will be syn',function (yargs) {

    })
    .example('syn a','all difInfo will be syn')
    .example('syn r 0 / syn r','syn all of rule')
    .example('syn c 12','syn id=5 in conf')
    .example('syn c 12 45','syn id 12~45 in conf')
    .help('h')
    .alias('h','help')
    .argv
/**
 * syn a|r|c  0|12|12 56
 * -a 同步全部
 * 0-同步 conf rule全部
 * 12 单单12
 * 12 56 12-56
 */


function syn() {
    let tableType =['a','c','r'];//0 1 2
    let GetRecordDifReq = new SynObj.GetRecordDifReq();

    GetRecordDifReq.difType = arguments[0][0].indexOf(tableType);

    if (arguments[0].length>2){//3-两个参数
        startId=arguments[0][1];
        endId = arguments[0][2];
    }else if(arguments[0].length>1){//2-一个参数
        startId=arguments[0][1];
        endId=startId;
    }else {//无参数
        startId=0;
        endId=0;
    }

    //获取difInfo - all
    return global.getConDif.getConInfo(GetRecordDifReq)
        .then(res => {
            let SynReq = new SynObj.SynReq();
            SynReq.startId=startId;
            SynReq.endId=endId;
            return Promise.resolve(global.synDbInfo.start(res,SynReq));
        })
        .then(res=>{
            return res;
        })
        .catch(err => {
            let a;
        });

}